package com.example.weather

import android.annotation.SuppressLint
import android.os.Bundle
import android.widget.EditText
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import org.xutils.common.Callback
import org.xutils.common.Callback.CommonCallback
import org.xutils.http.RequestParams
import org.xutils.x

/**
 * @author Y7993
 */
// 主活动类，用于获取并显示网页内容
class test : AppCompatActivity() {
    var et_url: EditText? = null
    var tv_show: TextView? = null

    @SuppressLint("SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_htmlview_xutil)
        et_url = findViewById<EditText>(R.id.et_url)
        et_url!!.setText("https://www.baidu.com")
        tv_show = findViewById<TextView>(R.id.tv_show)
    }

    // 处理获取HTML内容的逻辑
    fun getHtml() {
        val rp = RequestParams(et_url!!.text.toString().trim { it <= ' ' })
        x.http().get<String?>(rp, MyCallBack())
    }

    fun gethtml() {
    }

    // 自定义回调类，用于处理HTTP请求的结果
    inner class MyCallBack : CommonCallback<String?> {
        override fun onSuccess(result: String?) {
            tv_show!!.text = result
        }

        override fun onError(ex: Throwable?, isOnCallback: Boolean) {
        }

        override fun onCancelled(cex: Callback.CancelledException?) {
        }

        override fun onFinished() {
            println("完成")
        }
    }
}
